﻿//////////////////////////////////////////////////////////////////////////////
//
//  Copyright © 1998-2024 Glodon Company Limited.  All rights reserved.
//
//  Use of this software is subject to the terms of the Glodon license
//  agreement provided at the time of installation or download, or which
//  otherwise accompanies this software in either electronic or hard copy form.  
//
//////////////////////////////////////////////////////////////////////////////
#pragma once

// std headers
#include <vector>
#include <memory>

// qt headers

// gcmp headers

// custom headers
#include "BatchWorkflowBase.h"
#include "GbmpNew.h"

namespace gmepgcs
{
    template<typename TWorkflow, typename TArgument>
    class BatchWorkflow : public BatchWorkflowBase
    {
    public:
        explicit BatchWorkflow(const std::vector<TArgument> &arguments, QObject *parent = nullptr);
        virtual ~BatchWorkflow() = default;

    public:
        static BatchWorkflow<TWorkflow, TArgument> *Create(const std::vector<TArgument> &arguments, QObject *parent = nullptr);

    protected:
        virtual WorkflowBase *GetWorkflow(const int &index);

    private:
        std::vector<TArgument> m_vArgument;
    };


    template<typename TWorkflow, typename TArgument>
    inline BatchWorkflow<TWorkflow, TArgument>::BatchWorkflow(const std::vector<TArgument>& arguments, QObject * parent) :
        BatchWorkflowBase((int)arguments.size(), parent),
        m_vArgument(arguments)
    {
    }


    template<typename TWorkflow, typename TArgument>
    inline BatchWorkflow<TWorkflow, TArgument> * BatchWorkflow<TWorkflow, TArgument>::Create(const std::vector<TArgument>& arguments, QObject * parent)
    {
        return new BatchWorkflow<TWorkflow, TArgument>(arguments, parent);
    }

    template<typename TWorkflow, typename TArgument>
    inline WorkflowBase * BatchWorkflow<TWorkflow, TArgument>::GetWorkflow(const int & index)
    {
        if (index < 0)
        {
            return nullptr;
        }

        if (index >= m_vArgument.size())
        {
            return nullptr;
        }

        WorkflowBase *workflow = NEW_AS_QT(TWorkflow,m_vArgument[index]);
        return workflow;
    }
    
}